<template>
	<view class="content">
		<view class="topImg">
			<image class="topImg" src="/static/top.png"></image>
		</view>
		<!-- 切换语言 -->
		<!-- <view class="text-area" @click="changeLanguage">
			<text class="title">{{ app.language.selectLanguage }}</text>
			<image src="/static/qh.png"></image>
		</view> -->
		<!-- 搜索框 -->
		<!-- <view class="seach">
			<input type="text" :placeholder="app.language.gjz" v-model="seachTit" />
			<image src="/static/seach.png" @click="handleSeach"></image>
		</view> -->
		<!-- 轮播图 -->
		<!-- <swiper indicator-dots autoplay indicator-active-color="#2f8ef9" class="swiper">
			<swiper-item v-for="(item, index) in bannerList" :key="index">
				<image :src="item.url"></image>
			</swiper-item>
		</swiper> -->
		<!-- 连接页面 -->
		<view class="user" @click="handlegg">
			<image class="topImg" src="/static/user.png"></image>
			<view class="ggtext">
				<view class="bmfw">{{app.language.userInfo}}</view>
				<view class="wsb">{{app.language.djxg}}</view>
			</view>
		</view>
		<!-- <view class="gg" @click="handlegg">
			<image class="topImg" src="/static/gg.png"></image>
			<view class="ggtext">
				<view class="bmfw">{{app.language.bmfw}}</view>
				<view class="wsb">{{app.language.wsb}}</view>
			</view>
		</view>
		<view class="gg1" @click="handlegg">
			<image class="topImg" src="/static/gg1.png"></image>
			<view class="ggtext">
				<view class="bmfw">{{app.language.userInfo}}</view>
				<view class="wsb">{{app.language.djxg}}</view>
			</view> -->
		<!-- </view> -->
		<!-- 安全防范宣传 -->
		<!-- <view class="news">
			<view class="newsH">
				<image class="xc" src="/static/xc.png"></image>
				<text class="newsName">{{ app.language.newsName }}</text>
				<text class="newsMore" @click="newsMore">{{ app.language.newsMore }}</text>
			</view>
			<view class="newsItem" v-for="(item, index) in newsList" @click="newsShow(item.uuid)"
				v-if="newsList.length>0">
				<image :src="imgUrl+item.coverImage" class="newsImg"></image>
				<view class="newsB">
					<view class="newsTit">{{item.title}}</view>
					<view class="newscon">{{app.language.ly}}：{{item.source}}</view>
					<view class="newsTime">{{app.language.fbTime}}：{{item.createTime}}</view>
				</view>
			</view>
		</view> -->
		<!-- 户籍咨询 -->
		<view class="bmfwItem">
			<h3>{{app.language.ztfw}}</h3>
			<view class="hjzx" v-for="item in hjzxList" @click="hanldUrl(item.path)">
				<!-- @click="hanldUrl(item.path)" -->
				<view class="hjName">
					{{item.name}}
					<view class="motext">{{app.language.more}}</view>
				</view>
				<image :src="item.icon" class="icon"></image>
			</view>
			<view class="clear"></view>
		</view>
		<!-- <view class="kfBox" @click="handleKf">
			<image src="/static/aikf.png"></image>
		</view> -->
		<!-- 如果为数据为空显示暂无数据 -->
		<!-- <view v-if="newsList.length==0">
			<nullVue></nullVue>
		</view> -->
		<u-action-sheet @select="selectLanguageList" @close="closeLanguageList" :actions="languageList"
			:closeOnClickOverlay="true" :closeOnClickAction="true" :title="app.language.selectLanguage"
			:safeAreaInsetBottom="true" :show="showLanguageList">
		</u-action-sheet>

	</view>
</template>

<script>
	import {
		newsList
	} from '@/api/news.js'
	import nullVue from '@/components/null';
	const global = getApp().globalData;
	import config from '@/config'

	export default {
		components: {
			nullVue
		},
		data() {
			return {
				imgUrl: config.baseUrl,
				app: {
					global: global,
					name: global.appName,
					language: global.language
				},
				languageList: [{
						name: '简体中文'
					},
					{
						name: 'English'
					}
				],
				showLanguageList: false,
				bannerList: [],
				newsList: [],
				// 搜索关键词
				seachTit: "",
				hjzxList: [{
						icon: "/static/gjbl.png",
						path: "/pages/bmfw/domicile",
						name: ""
					},
					{
						icon: "/static/ldydj.png",
						path: "/pages/hotel/list",
						name: ""
					},
					{
						icon: "/static/xgzm.png",
						path: "/pages/related/index",
						name: ""
					},
					{
						icon: "/static/zfjd.png",
						path: "/pages/supervise/index",
						name: ""
					},
					{
						icon: "/static/czfw.png",
						path: "/pages/rentHouse/index",
						name: ""
					},
					{
						icon: "/static/ylcs.png",
						path: "/pages/enter/index",
						name: ""
					},
				],
				token: "",
				userInfo: {}
			}
		},
		onLoad() {
			this.hjzxList[0].name = this.app.language.hjbl
			this.hjzxList[1].name = this.app.language.ldydj
			this.hjzxList[2].name = this.app.language.kjxgzm
			this.hjzxList[3].name = this.app.language.zfjdts
			this.hjzxList[4].name = this.app.language.czfwbb
			this.hjzxList[5].name = this.app.language.ylcsdj
			this.getToken()
			this.getNews()
		},
		methods: {
			// 查询安全防范列表数据
			getNews() {
				uni.showLoading({
					title: this.app.language.jzz,
				});
				let data = {
					"": ""
				}
				newsList(data).then((res) => {
					if (res.code == 200) {
						uni.hideLoading();
						this.newsList = res.rows
						// 遍历banner数据
						for (let i = 0; i < res.total; i++) {
							let temp = {
								url: this.imgUrl + res.rows[i].coverImage,
							};
							this.bannerList.push(temp);
						}
					}
				})
			},
			// 获取缓存
			getToken() {
				let that = this
				uni.getStorage({
					key: 'loginData',
					success: function(res) {
						console.log('resres', res)
						// that.form.reportType = res.data.userInfo.peopleType
						that.token = res.data.userInfo.appToken
						that.userInfo = res.data.userInfo
						console.log('that.userInfo', that.userInfo)
					}
				});
				// debugger
			},

			// 跳转页面
			hanldUrl(item) {
				console.log('this.userInfo', this.userInfo)
				console.log('tokentoken', this.token)
				// uni.navigateTo({
				// 	url: item,
				// });
				if (item == '/pages/supervise/index' || item == '/pages/rentHouse/index' || item == '/pages/enter/index') {
					if (this.token) {
						if (this.userInfo.peopleType == "people") {
							if (!this.userInfo.userName && !this.userInfo.idcard &&
								!this.userInfo.idcardFront && !this.userInfo.idcardBack) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							} else {
								uni.navigateTo({
									url: item,
								});
							}
						} else if (this.userInfo.peopleType == "police") {
							// 身份作证号的
							if (!this.userInfo.agent) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.birthdate) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.idcard) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.nationality) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.policeNumber) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.personnelCategory) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.workTime) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.positionRank) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.marriage) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.height) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.weight) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							if (!this.userInfo.photo) {
								uni.showToast({
									title: this.app.language.improve,
									icon: 'none',
								});
								return
							}
							uni.navigateTo({
								url: item,
							});
							// if (!this.userInfo.agent && !this.userInfo.birthdate && !this.userInfo.birthdate && !this
							// 	.userInfo
							// 	.nationality && !this.userInfo.policeNumber &&
							// 	!this.userInfo.personnelCategory && !this.userInfo.department && !this.userInfo.workTime &&
							// 	!
							// 	this.userInfo.positionRank &&
							// 	!this.userInfo.marriage && !this.userInfo.height && !this.userInfo.weight && !this.userInfo
							// 	.photo) {
							// 	uni.showToast({
							// 		title: this.app.language.improve,
							// 		icon: 'none',
							// 	});
							// 	return
							// } else {
							// 	uni.navigateTo({
							// 		url: item,
							// 	});
							// }
						}
					} else {
						uni.navigateTo({
							url: '../login/login',
						});
					}
				} else {
					uni.navigateTo({
						url: item,
					});
				}
			},


			// 点击搜索查询数据
			handleSeach() {
				let data = {
					"title": this.seachTit
				}
				newsList(data).then((res) => {
					if (res.code == 200) {
						this.newsList = res.rows
					}
				})
			},

			selectLanguageList(e) {
				switch (e.name) {
					case '简体中文':
						uni.setStorageSync('language', 'chinese')
						this.changeLanguage('chinese')
						break

					case 'English':
						uni.setStorageSync('language', 'english')
						this.changeLanguage('english')
						break
				}
			},
			changeLanguage(value) {
				this.showLanguageList = true
				getApp().setLanguage(value)
				uni.setLocale()
				// 直接从全局数据更新本地数据
				this.app.language = getApp().globalData.language
			},
			closeLanguageList() {
				this.showLanguageList = false
			},
			popTest() {
				uni.showModal({
					title: this.app.language.popTitleText,
					cancelText: this.app.language.popCancelText,
					confirmText: this.app.language.popConfirmText,
					content: this.app.language.popTestContentText
				})
			},

			// 点击更多跳转到新闻列表页
			newsMore() {
				uni.navigateTo({
					url: '/pages/news/list',
				});
			},

			// 点击更多跳转到新闻详情页
			newsShow(uuid) {
				uni.navigateTo({
					url: '../news/show?uuid=' + uuid,
				});
			},
			// 广告连接
			handlegg() {
				if (this.token) {
					if (this.userInfo.peopleType == "people") {
						uni.navigateTo({
							url: '../user/peopleInfo',
						});
					} else if (this.userInfo.peopleType == "police") {
						uni.navigateTo({
							url: '../user/info',
						});
					}
				} else {
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			// 客服
			handleKf() {
				uni.reLaunch({
					url: '/pages/kefu/list'
				});
			}
		}
	}
</script>

<style>
	.content {
		background-color: #fff;
	}

	.topImg {
		width: 100%;
	}

	.text-area {
		font-size: 24rpx;
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		color: #fff;
	}

	.text-area image {
		width: 30rpx;
		height: 32rpx;
		position: relative;
		top: 7rpx;
		margin-left: 10rpx;
	}

	.seach {
		width: 90%;
		margin: 0 auto;
		display: flex;
		position: absolute;
		top: 110rpx;
		left: 0;
		right: 0;
	}

	.seach input {
		width: 88%;
		padding: 8rpx 25rpx;
		background-color: #fff;
		border-radius: 50rpx;
		font-size: 26rpx;
		color: #a7a7a7;
	}

	.seach image {
		width: 55rpx;
		height: 55rpx;
		margin-left: 10rpx;
		margin-top: 5rpx;
	}

	.swiper {
		height: 330rpx;
		background-color: #fff;
		width: 95%;
		margin: -124px auto 0;
		z-index: 9999;
		position: relative;
		box-shadow: 1px 1px 10rpx #ddd;
		border-radius: 10rpx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.swiper swiper-item {
		border-radius: 10rpx;
		text-align: center;
	}

	.news {
		margin-top: 25rpx;
		padding: 0 20rpx;
	}

	.newsItem {
		display: flex;
		background-color: #fff;
		margin-top: 10rpx;
		border-radius: 5rpx;
		padding: 10rpx;
		border-bottom: 1px solid #ddd;
	}

	.newsImg {
		width: 220rpx;
		height: 150rpx;
		margin-right: 20rpx;
	}

	.newsB {
		position: relative;
		width: 65%;
	}

	.newsTit {
		font-size: 26rpx;
		font-weight: bold;
		margin: 10rpx 0;
		overflow: hidden;
		display: -webkit-box;
		/* 将对象作为弹性伸缩盒子模型显示 */
		-webkit-line-clamp: 1;
		/* 行数，值可以改，表示展示X行后多余的缩略展示 */
		-webkit-box-orient: vertical;
		/* 设置或检索伸缩盒对象的子元素的排列方式 */
		word-break: break-all;
		line-height: 40rpx;
	}

	.newscon {
		font-size: 24rpx;
		color: #aeaeae;
		margin: 10rpx;
		overflow: hidden;
		display: -webkit-box;
		/* 将对象作为弹性伸缩盒子模型显示 */
		-webkit-line-clamp: 2;
		/* 行数，值可以改，表示展示X行后多余的缩略展示 */
		-webkit-box-orient: vertical;
		/* 设置或检索伸缩盒对象的子元素的排列方式 */
		word-break: break-all;
		line-height: 40rpx;
		height: 76rpx;
	}

	.newsTime {
		font-size: 22rpx;
		color: #aeaeae;
		position: absolute;
		bottom: 10rpx;
	}

	.newsH {
		/* font-size: 28rpx;
		font-weight: bold; */
	}

	.newsH text {
		width: 46%;
		display: inline-block;
	}

	.newsName {
		font-size: 28rpx;
		font-weight: bold;
	}

	.newsMore {
		font-size: 24rpx;
		color: #b9b9b9;
		text-align: right;
	}

	.gg,
	.gg1 {
		width: 50%;
		height: 170rpx;
		width: 46%;
		margin: 20rpx auto;
		border-radius: 10rpx;
		position: relative;
		float: left;
		margin-left: 20rpx;
	}

	.gg image,
	.gg1 image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.ggtext,
	.ggtext {
		position: absolute;
		top: 33rpx;
		right: 32rpx;
	}

	.bmfw {
		font-size: 29rpx;
		color: #2270f3;
		margin-bottom: 18rpx;
		font-weight: bold;
		/* font-style: italic; */
		letter-spacing: 2rpx;
		/* 增加字符间距 */
	}

	.gg1 .bmfw {
		color: #f3b622 !important;
	}

	.gg1 .wsb {
		background-color: #f3b622 !important;
	}

	.wsb {
		font-size: 21rpx;
		color: #fff;
		background-color: #2270f3;
		/* border-radius: 50%; */
		padding: 10rpx;
		text-align: center;
		border-radius: 27rpx;
		width: 157rpx;
	}

	.xc {
		width: 45rpx;
		height: 40rpx;
		position: relative;
		top: 10rpx;
	}

	.kfBox {
		/* background-color: #2f8ef9; */
		color: #fff;
		font-size: 22rpx;
		text-align: center;
		/* width: 100rpx;
		height: 100rpx; */
		/* padding: 20rpx; */
		border-radius: 50%;
		/* box-shadow: 1px 1px 10rpx #ddd; */
		position: absolute;
		bottom: 244rpx;
		right: 0;
	}

	.kfBox image {
		width: 110rpx;
		height: 110rpx;
	}

	.bmfwItem {
		/* padding: 20rpx; */
		width: 100%;
		margin: 0 auto;
	}

	.bmfwT {
		font-weight: bold;
		font-size: 24rpx;
		margin-bottom: 20rpx;
		border-left: 2px solid #2f8ef9;
		padding-left: 10rpx;
	}

	.hjzx {
		font-size: 26rpx;
		width: 44%;
		float: left;
		box-shadow: 1px 1px 10rpx #ddd;
		text-align: center;
		padding: 41rpx 0;
		margin: 20rpx;
		border-radius: 10rpx;
		box-shadow: 1px 1px 10rpx #ddd;
	}

	/* .hjzx:nth-child(1) {
		background-image: linear-gradient(to right, #f0f1ff, #e0e0f7);
	} */

	.hjzx:nth-child(2) {
		background-image: linear-gradient(to right, #f0f1ff, #e0e0f7);
	}

	.hjzx:nth-child(3) {
		background-image: linear-gradient(to right, #e6faff, #d8f8fd);
	}

	.hjzx:nth-child(4) {
		background-image: linear-gradient(to right, #fff6f5, #f8e6dd);
	}

	.hjzx:nth-child(5) {
		background-image: linear-gradient(to right, #f0fcfe, #d0e8f9);
	}

	.hjzx:nth-child(6) {
		background-image: linear-gradient(to right, #f3f3ff, #e9eafd);
	}

	.hjzx:nth-child(7) {
		background-image: linear-gradient(to right, #eafaff, #caf2ef);
	}

	.clear {
		clear: both
	}

	.topImg {
		position: relative;
	}

	.topImg image {
		width: 100%;
		height: 300rpx;
	}

	.topText {
		color: #3675fe;
		position: absolute;
		top: 80rpx;
		left: 40rpx;
	}

	.topText1 {
		font-size: 41rpx;
		font-weight: bold;
	}

	.topText2 {
		font-size: 24rpx;
		color: #3675fe;
		margin-top: 10rpx;
		margin-left: 20rpx;
	}

	.icon {
		width: 60rpx;
		height: 59rpx;
		float: right;
		margin-right: 35rpx;
		position: relative;
		top: 14rpx;
	}

	.hjName {
		margin-top: 10rpx;
		float: left;
		margin-left: 35rpx;
		font-size: 30rpx;
		font-weight: bold;
		text-align: left;
	}

	.motext {
		font-size: 22rpx;
		margin-top: 14rpx;
		color: #727170;
		font-weight: 500;
	}

	.popup {
		z-index: 9999;
		position: relative;


	}

	.Ptitle {
		background-color: #fff;
		width: 512rpx;
		padding: 50rpx;
		text-align: center;
		border-radius: 10rpx;
	}

	.Ptitle button {
		font-size: 28rpx;
		background: #2f8ef9;
		color: #fff;
	}

	.gb {
		width: 30rpx !important;
		height: 30rpx !important;
		position: absolute;
		top: 10rpx;
		right: 10rpx;
		width: 90%;
	}

	.user {
		width: 100%;
		height: 170rpx;
		width: 95%;
		margin: 20rpx auto;
		border-radius: 10rpx;
		position: relative;
	}

	.user image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.ggtext {
		position: absolute;
		top: 22rpx;
		left: 124rpx;
	}

	.bmfw {
		font-size: 37rpx;
		color: #2270f3;
		margin-bottom: 18rpx;
		font-weight: bold;
		/* font-style: italic; */
		letter-spacing: 4rpx;
		/* 增加字符间距 */

	}

	.wsb {
		font-size: 23rpx;
		color: #fff;
		background-color: #2270f3;
		/* border-radius: 50%; */
		padding: 10rpx;
		text-align: center;
		border-radius: 27rpx;
	}

	.bmfwItem h3 {
		color: #3f3f3f;
		padding-left: 20rpx;
		font-size: 30rpx;
		margin-top: 10rpx;
	}
</style>